﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MS_UI
{
    public partial class Frm_DeviceControl : Form
    {
        public Frm_DeviceControl()
        {
            InitializeComponent();
        }

        string StartAddress = string.Empty;
        string StopAddress = string.Empty;

        public Frm_DeviceControl(string DeviceName,string StartAddress,string StopAddress)
        {
            InitializeComponent();
            this.StartAddress = StartAddress; 
            this.StopAddress = StopAddress;
            this.lbl_StartName.Text = "开启" + DeviceName;
            this.lbl_StopName.Text = "关闭" + DeviceName;
        }

        private void btn_Start_Click(object sender, EventArgs e)
        {
            CommonMethod.IsWriting = true;
            Thread.Sleep(500);
            bool res1 = CommonMethod.objMod.PreSetFloatKeepReg(CommonMethod.Address, int.Parse(this.StartAddress), 256) ;
            bool res2 = CommonMethod.objMod.PreSetFloatKeepReg(CommonMethod.Address, int.Parse(this.StartAddress), 0) ;
            if (res1 && res2)
            {
                MessageBox.Show(this.lbl_StartName.Text + "成功","设备开启");
            }
            else
            {
                MessageBox.Show(this.lbl_StartName.Text + "失败", "设备开启");
            }
            CommonMethod.IsWriting = false;
        }

        private void btn_Stop_Click(object sender, EventArgs e)
        {
            CommonMethod.IsWriting = true;
            Thread.Sleep(500);
            bool res1 = CommonMethod.objMod.PreSetFloatKeepReg(CommonMethod.Address, int.Parse(this.StopAddress), 256);
            bool res2 = CommonMethod.objMod.PreSetFloatKeepReg(CommonMethod.Address, int.Parse(this.StopAddress), 0);
            if (res1 && res2)
            {
                MessageBox.Show(this.lbl_StopName.Text + "成功", "设备关闭");
            }
            else
            {
                MessageBox.Show(this.lbl_StopName.Text + "失败", "设备关闭");
            }
            CommonMethod.IsWriting = false;
        }
    }
}
